package cn.edu.njust.control;

import cn.edu.njust.pojo.Result;
import cn.edu.njust.util.ExcelUtils;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

//@WebServlet(name = "resultServlet", value = "/resultServlet")
public class ResultServlet extends HttpServlet {

    protected void doGet(@RequestPart("files") MultipartFile file) throws Exception{
        List<Result> results = ExcelUtils.readMultipartFile(file, Result.class);
        System.out.println("123");
        for (Result result : results){
            System.out.println(result.toString());
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("UTF-8");
        this.doGet(request, response);
    }
}
